/* examplelex.l - skaner wspolpracujacy z parserem example.y */
%{
	#include <stdlib.h>
	#include <stdio.h>
	#include <strings.h>
    	int o_bracket, c_bracket;
%}

/* zmienna globalna yylval sluz do przekazywania parserowi atrybutu tokenu (wartosci semantycznej);
   zmienna yylval powinna jest typu YYSTYPE */
%%


asm         { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return ASM; }
auto        { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return AUTO; }
bool        { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return BOOL; }
break       { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return BREAK; }
case        { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return CASE; }
catch       { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return CATCH; }
char        { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return CHAR; }
class       { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return CLASS; }
const       { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return CONST; }
continue    { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return CONTINUE; }
default     { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return DEFAULT; }
delete      { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return DELETE; }
do          { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return DO; }
while       { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return WHILE; }
double      { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return DOUBLE; }
else        { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return ELSE; }
enum        { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return ENUM; }
extern      { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return EXTERN; }
float       { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return FLOAT; }
for         { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return FOR; }
friend      { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return FRIEND; }
goto        { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return GOTO; }
inline      { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return INLINE; }
int         { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return INT; }
long        { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return LONG; }
namespace   { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return NAMESPACE; }
new         { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return NEW; }
operator    { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return OPERATOR; }
private     { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return PRIVATE; }
protected   { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return PROTECTED; }
public      { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return PUBLIC; }
register    { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return REGISTER; }
return      { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return RETURN; }
short       { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return SHORT; }
signed      { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return SIGNED; }
sizeof      { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return SIZEOF; }
static      { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return STATIC; }
struct      { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return STRUCT; }
switch      { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return SWITCH; }
template    { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return TEMPLATE; }
this        { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return THIS; }
throw       { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return THROW; }
try         { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return TRY; }
typedef     { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return TYPEDEF; }
union       { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return UNION; }
unsigned    { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return UNSIGNED; }
using       { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return USING; }
virtual     { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return VIRTUAL; }
void        { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return VOID; }
volatile    { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return VOLATILE; }
wchar_t     { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return WCHAR_T; }



#include[ \t]*\"[a-zA-Z0-9.]*\" { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return INCLUDE_LC; }
#include[ \t]*<[a-zA-Z0-9.]*>   { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return INCLUDE_GL; } 
#debug { ECHO; }
#if { ECHO; }
#[a-zA-z]* { printf("Nie rozpoznana dyrektywa %s", yytext); }

if[ \t]*(.*)[^{]*  { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return IF; }

"("     { return yytext[0]; }
")"     { return yytext[0];}

"{"     {  o_bracket++; if( o_bracket < c_bracket ) printf("Klamry nie banglają"); return yytext[0]; }
"}"     {  c_bracket++; if( o_bracket < c_bracket ) printf("Klamry nie banglają"); return yytext[0];  }

"="     { return yytext[0]; }
"!"     { return yytext[0]; }
"<"     { return yytext[0]; }
">"     { return yytext[0]; }

.*;	{ yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return CODE_LINE; }

[a-zA-Z]*[a-zA-Z0-9]*   { yylval.name = malloc(yyleng);  strcpy(yylval.name , yytext); return NAME; }

[ \n\t] { ;}
.         { return yytext[0];};
